import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
//按需引入elementui
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

//引入icon
// import Icons from 'unplugin-icons/vite'
// import IconsResolver from 'unplugin-icons/resolver'
// import Inspect from 'vite-plugin-inspect'

import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
        AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  server: {
    port: "5175",
    open: true,
    proxy: {
      "/api": {
        // target: "http://47.97.4.134:8005",
        target: "http://localhost:8005",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ""),
      },
      "/cgi/data.php": {
        target: "http://cgq.hmsensor.com",
        changeOrigin: true,
      },
      "/apr": {
        target: "http://cgq.hmsensor.com",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/apr/, ""),
      },
    },
  },
})
